﻿@model Bricks.Site.Models.ProjectContract.FinishedProjectInfoView

@{
    ViewBag.Title = "完工项目概况";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        initTable();
    });
    function initTable(queryData) {
        $('#projectDataGrid').datagrid({
            url: '/ProjectInfo/GetFinishedDataList',
            //title: '功能管理',  //标识
            iconCls: 'icon-bricks',
            //width: 'auto',
            //height: 500,
            nowrap: true,
            autoRowHeight: false,
            striped: true,
            collapsible: true,
            pagination: false,
            //pageSize: 20,
            rownumbers: true,
            //sortName: 'ID',    //根据某个字段给easyUI排序
            //sortOrder: 'asc',
            remoteSort: false,
            idField: 'ID',
            checkOnSelect: true,
            selectOnCheck: true,
            singleSelect: true,
            queryParams: queryData,  //异步查询的参数
            toolbar: '#projectToolBar',
            columns: [[
                { title: '@Html.LabelFor(model => model.ProjectName)', field: 'ProjectName', width: 250, sortable: true },
                { title: '@Html.LabelFor(model => model.FinishTime)', field: 'FinishTime', width: 80, sortable: true },
                { title: '@Html.LabelFor(model => model.PlanAccount)', field: 'PlanAccount', width: 100, sortable: true },
                { title: '@Html.LabelFor(model => model.FinalAccount)', field: 'FinalAccount', width: 100, sortable: true },
                { title: '@Html.LabelFor(model => model.OfficialNum)', field: 'OfficialNum', width: 200, sortable: true },
                { title: '@Html.LabelFor(model => model.OfficialTime)', field: 'OfficialTime', width: 80, sortable: true },
                { title: '@Html.LabelFor(model => model.RegisterDepartmentAndUser)', field: 'RegisterDepartmentAndUser', width: 250, sortable: true }
            ]],
            //非发布人禁用修改和删除按钮
            onClickRow: function (rowIndex, rowData) {
                if (rowData.RegisterUserID != rowData.LoginUserID) {
                    $('#btnModify').linkbutton('disable');
                    $('#btnDelete').linkbutton('disable');
                }
                else {
                    $('#btnModify').linkbutton('enable');
                    $('#btnDelete').linkbutton('enable');
                }
            },
            //双击弹出预览
            onDblClickRow: function (rowIndex, rowData) {
                FinishedProjectInfo.Preview();
            }
        });
    }
    var FinishedProjectInfo = {
        //新增
        Add: function () {
            FinishedProjectInfo.Mutual("新增", "/ProjectInfo/FinishedEdit", true);
        },

        //修改
        Modify: function () {
            var row = $("#projectDataGrid").datagrid("getSelected");
            if (row) {
                FinishedProjectInfo.Mutual("修改", "/ProjectInfo/FinishedEdit?ID=" + row.ID);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //实体操作
        Mutual: function (title, href, isAdd) {
            $.ModelDialog({
                title: title, href: href, width: 690,
                handler: function () {
                    $.ModelForm({
                        validate: true, button: $(this),
                        id: "#project-model",
                        url: "/ProjectInfo/FinishedEditPost",
                        success: function (result) { FinishedProjectInfo.Reload(); }
                    });
                },
                onLoad: function () { FinishedProjectInfo.FormInit(isAdd); }
            });
        },

        //弹窗初始化
        FormInit: function (isAdd) {

        },


        //预览
        Preview: function () {
            var row = $("#projectDataGrid").datagrid("getSelected");
            if (row) {
                FinishedProjectInfo.PreviewMutual("预览", "/ProjectInfo/FinishedPreview?id=" + row.ID);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //实体操作
        PreviewMutual: function (title, href) {
            $.ModelDialog({
                title: title, href: href, width: 690,
                onLoad: function () { }
            });
        },

        //删除
        Delete: function () {
            var arr = $('#projectDataGrid').datagrid('getSelections');

            if (arr.length == 1) {
                $.messager.confirm('操作提示', "确认删除[ " + arr[0].ProjectName + " ]吗？", function (r) {
                    if (r) {
                        $.post("/ProjectInfo/FinishedDelete?ID=" + arr[0].ID, { query: arr.join(",") }, function (result) {
                            if (result.ResultType == 0) {  //0表示成功
                                //移除删除的数据
                                //$("#myTreeGrid").datagrid("reload");
                                //$("#myTreeGrid").datagrid("clearSelections");
                                //$.messager.alert('操作提示', '删除成功!', 'info');
                                $.EasyuiSlide(result.Message);
                                FinishedProjectInfo.Reload();
                            }
                            else {
                                $.EasyuiMsg(result.Message);
                            }
                        });
                    }
                });

            } else {
                //$.messager.alert('操作提示', '请选择一条数据!', 'warning');
                $.EasyuiMsg("请选择一条数据");
            }
            return false;
        },

        //刷新
        Reload: function () {
            $("#projectDataGrid").datagrid("reload");
        }
    }
</script>

<div class="easyui-panel" title="项目列表" fit="true">
    <table id="projectDataGrid" fit="true"></table>
    @*<div id="projectToolBar">
            <a href='javascript:void(0)' class='easyui-linkbutton' onclick='FinishedProjectInfo.Add()' data-options='plain:true,iconCls:"icon-application_add"'>新增</a>
            <a href='javascript:void(0)' class='easyui-linkbutton' onclick='FinishedProjectInfo.Modify()' data-options='plain:true,iconCls:"icon-application_delete"'>修改</a>
            <a href='javascript:void(0)' class='easyui-linkbutton' onclick='FinishedProjectInfo.Delete()' data-options='plain:true,iconCls:"icon-bell"'>删除</a>
            <a href='javascript:void(0)' class='easyui-linkbutton' onclick='FinishedProjectInfo.Disable()' data-options='plain:true,iconCls:"icon-bank"'>禁用</a>
            <a href='javascript:void(0)' class='easyui-linkbutton' onclick='FinishedProjectInfo.Enable()' data-options='plain:true,iconCls:"icon-bestseller"'>启用</a>
            <a href='javascript:void(0)' class='easyui-linkbutton' onclick='FinishedProjectInfo.Up()' data-options='plain:true,iconCls:"icon-up"'>向上</a>
            <a href='javascript:void(0)' class='easyui-linkbutton' onclick='FinishedProjectInfo.Down()' data-options='plain:true,iconCls:"icon-down"'>向下</a>
            <a href='javascript:void(0)' class='easyui-linkbutton' onclick='FinishedProjectInfo.Reload()' data-options='plain:true,iconCls:"icon-blue_lego"'>刷新</a>
        </div>*@
    <div id="projectToolBar">@Html.Raw(ViewBag.ToolBarInfo)</div>
</div>